package gov.pbc.nn.kjgl.software.dao;

import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import gov.pbc.nn.core.dao.AbstractHibernateDao;
import gov.pbc.nn.kjgl.entity.ArchivesContent;
import gov.pbc.nn.kjgl.entity.Project;
import gov.pbc.nn.kjgl.entity.ProjectFile;
import gov.pbc.nn.kjgl.entity.ProjectMember;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.bstek.dorado.data.provider.Criteria;
import com.bstek.dorado.data.provider.Page;

@Repository
public class ProjectMangeDao extends AbstractHibernateDao {

	/**
	 * 分页查询，并根据id查询
	 * @param page
	 * @param pid
	 */
	public void getProjectMenberByPid(Page<ProjectMember> page, String pid) {
		DetachedCriteria query = DetachedCriteria.forClass(ProjectMember.class);
		query.add(Restrictions.or(Restrictions.eq("invalid", false), Restrictions.isNull("invalid")));
		query.add(Restrictions.eq("projectId", pid));
		this.pagingQuery(page, query);
	}

	/**
	 * 保存实体类
	 * @param projectmember
	 */
	public void saveProjectMember(ProjectMember projectmember) {
		this.save(projectmember);
	}

	/**
	 * 根据id进行删除
	 * @param id
	 */
	public void deletePMember(String id) {
//		String hql = "from ProjectMember where invalid=false and projectId=:projectId";
//		Map<String, Object> map = new HashMap<String, Object>();
//		map.put("projectId", id);
//		List<ProjectMember> pf = this.query(hql, map);
//		if (!pf.isEmpty()) {
			this.delete(id, ProjectMember.class);
//		}
	}
	
	public void getPageAll(Page<Project> page, Criteria criteria) {
		 DetachedCriteria query = this.buildDetachedCriteria(criteria,
		 Project.class);
		 query.add(Restrictions.or(Restrictions.eq("invalid", false),
		 Restrictions.isNull("invalid")));
		 query.add(Restrictions.eq("state", 10));
		 this.pagingQuery(page, query);
	}
}
